type Target = {
	[key: string]: any;
}

/**
 * 查找根节点
 * @param id ：节点id
 * @param target：目标数组
 * @returns 根节点元素
 */
export const findRootNode = (id: string | number, target: Target[]) => {
	const findParent = (currentId: string | number) => {
		const currentElement = target.find((item) => item.id === currentId);
		if (!currentElement) return null;

		if (currentElement.parentId === '0') {
			return currentElement;
		} else {
			return findParent(currentElement.parentId);
		}
	};
	return findParent(id);
};
